import {
	useUserStore
} from "@/stores/index.js"

export const setupIntercepors = () => {
	let needLogin = ['/ExplorePackage/Publish/Publish', '/UserCenterPackage/UserInfo/UserInfo',
		'/UserCenterPackage/Orders/Orders', '/UserCenterPackage/Collection/Collection',
		'/UserCenterPackage/Evaluate/Evaluate', '/UserCenterPackage/Post/Post', '/UserCenterPackage/Wallet/Wallet',
		'/ComprehensivePackage/Booking/Booking'
	]
	let list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
	list.forEach(item => {
		uni.addInterceptor(item, {
			invoke(e) {
				const UserStore = useUserStore()
				const token = UserStore.UserInfoList.token
				const url = e.url.split('?')[0]
				if (needLogin.includes(url) && !token) {
					uni.navigateTo({
						url: '/UserCenterPackage/Login/Login'
					})
					return false
				}
				return true
			}
		})
	})
}